#include "circle.h"
#include <QPen>
#include <QPainter>

Circle::Circle(qreal x1, qreal y1, qreal r):QGraphicsEllipseItem(x1-r,y1-r,2*r,2*r){
    m_center = new QPointF(x1,y1);
    m_radius = r;
}

void
Circle::setCenter(qreal nx1, qreal ny1){
    setRect(nx1-m_radius, ny1-m_radius, 2*m_radius, 2*m_radius);
    m_center->setX(nx1);
    m_center->setY(ny1);
}

void
Circle::setRadius(qreal r){
     setRect(m_center->x()-r,m_center->y()-r,2*r,2*r);
     m_radius = r;
}

void
Circle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    if(isSelected()){
        QPen pen;
        pen.setColor(Qt::red);
        pen.setWidth(3);
        painter->setPen(pen);
        painter->drawEllipse(*m_center,m_radius,m_radius);
    } else {
        QGraphicsEllipseItem::paint(painter,option,widget);
    }
}
